package com.elitel.common.businessJdbc.sqlserver;

import com.elitel.common.businessJdbc.BusinessSelectPreparedStatement;

public class SqlServerSelectPreparedStatement extends BusinessSelectPreparedStatement{

// case "SQLSERVER":
//     // sqlserver数据库排序特殊处理
//     String newsort = sort.replaceAll("AA.", "a.");
//     // 条件查询语句
//     page_sql =
//             "select * from(select ROW_NUMBER() OVER ("
//                     + newsort
//                     + ") RN,a.* from(select "
//                     + fields
//                     + " from "
//                     + tables
//                     + " )a where 1=1 "
//                     + whereSql
//                     + ")b WHERE  RN Between "
//                     + (startSize + 1)
//                     + " and "
//                     + endSize;
//     break;
//     can reference oracle

    // default mysql syntax;

    // public String getPrecompileSql(){
    //     return "";

    // }

   @Override
    public String getPrecompileSql(){
        // here is page or not pageable
        StringBuilder sb = new StringBuilder();
        sb.append(" select ")
            .append(getFieldSection())
            .append(" FROM ")
            .append(getTableSection())
            .append(" where 1=1 ")
            .append(containPlaceHolderCondition());

        if(isPageable()){
             sb.append(getOrderSection())
                 .append(" offset ")
                 .append( (pageNumber - 1) * pageSize)
                 .append(" rows fetch next ")
                 .append(pageSize)
                 .append(" rows only ");
        }

        return sb.toString();
    }



}
